<template>
  <div class="box">
    <el-row>
      <el-col :span="24">
        <div class="header">
          <el-form
            ref="form"
            :model="form"
            label-width="100px"
            class="flex-start"
          >
            <el-form-item label="所属月份" prop="reportingPeriod">
              <el-date-picker
                v-model="form.time"
                style="width: 650px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="mxDateChange"
              />
            </el-form-item>
            <el-form-item label="承包区名称" prop="contractAreaName">
              <el-select
                v-model="form.contractAreaName"
                placeholder="请选择承包区名称"
                style="width: 275px"
              >
                <el-option
                  v-for="(item, index) in ContractAreaList"
                  :key="index"
                  :label="item.networkName"
                  :value="item.networkName"
                />
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="search">查询</el-button>
              <el-button @click="mxClear">重置</el-button>
              <el-button plain icon="el-icon-upload2">导出</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <div>
          <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            border
            max-height="600"
          >
            <el-table-column
              align="center"
              prop="reportingPeriod"
              label="所属月份"
              width="120"
            />
            <el-table-column
              align="center"
              prop="contractAreaName"
              label="承包区名称"
            />
            <el-table-column
              align="center"
              prop="disbursementAmount"
              label="派费金额"
              width="120"
            />
            <el-table-column
              align="center"
              prop="rebateAmount"
              label="返利金额"
            />
            <el-table-column
              align="center"
              prop="storageCharge"
              label="包仓费"
            />
            <el-table-column
              align="center"
              prop="excessTransitCharge"
              label="超额中转费"
            />
            <el-table-column
              align="center"
              prop="comprehensiveCost"
              label="综合费用"
            />
            <el-table-column
              align="center"
              prop="indemnityIncome"
              label="赔款收入"
            />
            <el-table-column
              align="center"
              prop="indemnityPayment"
              label="赔款支出"
            />
            <el-table-column
              align="center"
              prop="deductionAmount"
              label="减免金额"
            />
            <el-table-column
              align="center"
              prop="actualAmount"
              label="实付金额"
            />
          </el-table>
        </div>
      </el-col>
    </el-row>
    <div class="block" style="display: flex; justify-content: flex-end">
      <el-pagination
        :current-page="pages.pageNum"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pages.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import {
  getOutletsList,
  getSubjectFirstList,
  getSubjectList,
  // subjectSearch,
  // addSubject
} from "@/api/dashboard";
import { PaymentSummaryinit } from "@/api/apifile/Networkfinance";
export default {
  data() {
    return {
      ContractAreaList: [],
      form: {},
      formLabelWidth: "120px",
      addForm: {
        networkNameId: "",
        firstId: "",
        secondName: "",
      },
      loading: false,
      // 一级网点
      SubjectFirstList: [],
      // 网点列表
      networkList: [],
      pages: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,

      dialogFormVisible: false,
      currentPage4: 4,
      tableData: [],
      rules: {
        networkNameId: [
          { required: true, message: "请选择网点名称", trigger: "blur" },
        ],
        firstId: [
          { required: true, message: "请选择一级科目", trigger: "blur" },
        ],
        secondName: [
          { required: true, message: "请选择二级科目", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    // this.getList();
    // this.getOutLet();
    // this.getSubjectFirst();
    getOutletsList().then((res) => {
      this.ContractAreaList = res.data;
      // console.log("承包区名称", res);
    });
  },
  methods: {
    handleSizeChange(val) {
      this.pages.pageSize = val;
      this.init({ ...this.form, pageDate: this.pages });
    },
    handleCurrentChange(val) {
      this.pages.pageNum = val;
      this.init({ ...this.form, pageDate: this.pages });
    },
    mxClear() {
      this.$refs.form.resetFields();
    },
    mxDateChange(value) {
      // console.log("日期", value);
      this.form.startTime = value[0];
      this.form.endTime = value[1];
    },
    search() {
      this.$refs.form.validate((res) => {
        if (res) {
          this.init({ ...this.form, pageDate: this.pages });
        }
      });
    },
    init(obj) {
      this.loading = true;
      PaymentSummaryinit(obj).then((res) => {
        if (res.code === 200) {
          this.loading = false;
          this.tableData = res.data.data;
          this.total = res.data.total;
          this.pages.pageNum = res.data.current;
        }
      });
    },
    // 获取网点列表
    getOutLet() {
      getOutletsList().then((res) => {
        if (res.code === 200) {
          this.networkList = res.data;
        }
      });
    },
    // 获取一级网点下拉框
    getSubjectFirst() {
      getSubjectFirstList().then((res) => {
        if (res.code === 200) {
          this.SubjectFirstList = res.data;
        }
      });
    },
    // 显示表格数据
    getList() {
      getSubjectList().then((res) => {
        if (res.code === 200) {
          this.tableData = res.data.data;
          this.total = res.data.total;
          this.pages = res.data.pages;
        } else {
          this.$message({
            message: res.msg,
            type: "warning",
          });
        }
      });
    },
    // 打开弹窗
    onSubmit() {
      this.dialogFormVisible = true;
    },
    // 重置
    // clear() {
    //   this.form = {};
    //   this.getList();
    // },
    // handleSizeChange(val) {
    //   this.pages.pageSize = val;
    //   this.getList();

    //   // console.log(`每页 ${val} 条`);
    // },
    // handleCurrentChange(val) {
    //   this.pages.pageNum = val;
    //   this.getList();
    //   // console.log(`当前页: ${val}`);
    // },
    // handleSelectionChange(val) {
    //   // this.multipleSelection = val;
    // },
  },
};
</script>

<style lang="scss" scoped>
.box {
  padding: 20px;
}

.flex {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
}

.flex-start {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
}

.flex-bettom {
  display: flex;
  justify-content: space-between;
}

.header {
  padding-bottom: 20px;
  border-bottom: 1px solid #ccc;
}

.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
